﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Presentation.Models;
using System.Configuration;
using System.Data.SqlClient;

using Models;
using DataManager;




namespace Presentation.Controllers
{   

    public class FilmController : Controller
    {

        private DBAccess dbAccess = DBAccess.getInstance();

        //
        // GET: /Film/

        public ActionResult Index()
        {
            return View(dbAccess.getListFilms());
        }


        //
        // GET: /Film/Details/

        public ActionResult Details(int id)
        {
            Film monFilm = dbAccess.getFilm(id);
            //test
            return View(monFilm);
        }

        //
        // GET: /Film/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Film/Create

        [HttpPost]
        public ActionResult Create(Film _film)
        {
            try
            {
                dbAccess.createFilm(_film);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Film/Edit/5
 
        public ActionResult Edit(int id)
        {
            Film monFilm = dbAccess.getFilm(id);

            return View(monFilm);
        }

        //
        // POST: /Film/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Film _film)
        {
            try
            {
                dbAccess.updateFilm(_film);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Film/Delete/5
 
        public ActionResult Delete(int id)
        {
            Film deletedFilm = dbAccess.getFilm(id);
            return View(deletedFilm);
        }

        //
        // POST: /Film/Delete/5

        [HttpPost]
        public ActionResult Delete(Film _film)
        {
            try
            {
                dbAccess.deleteFilm(_film.Id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }

        }
    }
}
